<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');

need_manager();

if (is_post()) {
	if ($_POST['action'] == 'authorization') {
		$auth_file = dirname(dirname(dirname(__FILE__))) . '/auth/' . $_POST['id'] . '_auth.php';
		$auth_file = str_replace("\\", '/', $auth_file);
		file_put_contents($auth_file, "<?php \n".'$'."user_auth_info = array(" . $_POST['id'] . " => ".var_export($_POST['auth'], true).");"."\n ?>");
	}
	Session::Set('notice', '管理员授权成功');
	redirect($_SERVER['HTTP_REFERERE']);
}

/* build condition */
$condition = array('manager'=>'Y', 'proxy_id' => $login_user['proxy_id']);
$count = Table::Count('user', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 20);

$users = DB::LimitQuery('user', array(
	'condition' => $condition,
	'order' => 'ORDER BY id DESC',
	'size' => $pagesize,
	'offset' => $offset,
));

include template('manage_user_manager');
